﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dqs_BLL;
using Dqs_DAL;
using Model;
using Sunny.UI;

namespace Dqs_UI
{
	public partial class frmUpdateStudent : UIForm
	{
		public frmUpdateStudent(int id)
		{
			InitializeComponent();
			this.Id = id;
		}

		int Id { get; set; }
		Student_BLL student_BAL = new Student_BLL();

		private void frmUpdateStudent_Load(object sender, EventArgs e)
		{
			StudentInfo studentInfo = student_BAL.GetStudents().Where(a => a.Id == Id).FirstOrDefault()!;
			txtStuNum.Text = studentInfo.StuNum;
			txtUserName.Text = studentInfo.UserName;
			txtPwd.Text = studentInfo.Password;
			txtFullName.Text = studentInfo.FullName;
			txtPhone.Text = studentInfo.Phone;
		}

		private void uiButton1_Click(object sender, EventArgs e)
		{
			StudentInfo studentInfo = new StudentInfo();
			studentInfo.Id = Id;
			studentInfo.StuNum = txtStuNum.Text.Trim();
			studentInfo.UserName = txtUserName.Text.Trim();
			studentInfo.Password = txtPwd.Text.Trim();
			studentInfo.FullName = txtFullName.Text.Trim();
			studentInfo.Phone = txtPhone.Text.Trim();
			
			if (student_BAL.UpdateStudentInfoById(studentInfo))
			{
				DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("请检查输入内容是否正确！");
			}
		}
	}
}
